<?php
include '../libraries/config.php';
include '../libraries/dbclass2.php';
include '../libraries/cache.php';

if(isset($_GET['all'])){
$db=new db;
$db->connect();
$db->query("select id,manga from chapterk2 where bk=0 and check_error=0 and check_link=1 order by id asc limit 0,5000");


$re=$db->fetchAll();
echo serialize($re);
$db->close();
}

if(isset($_GET['detail'])){
	$id=$_GET['id'];
	$db=new db;
	$db->connect();
	$db->query("select * from chapterk_content where  chap_id=$id");
	$re=$db->fetchOne();
	echo serialize($re);
	$db->close();
}

if(isset($_GET['update'])){
	echo "Backup ".$_GET['chap_id']."<Br/>";
	$result=urldecode($_POST['content']);
	$manga=$_GET['manga'];
	$chap=$_GET['chap_id'];
	
	
	$result=unserialize($result);
	$db=new db;
	$db->connect();
	$db->nonquery("update  chapterk2 set bk=1 where id=".intval($_GET['chap_id']));
	
	
	$db->nonquery("delete from chapterk_content_bk where chap_id=".intval($_GET['chap_id']));
		echo "Delete".mysql_error();
	//	$sql="insert into chapterk_content_bk(chap_id,manga,chap_content,error) values(".$chap.",".$manga.",'".$result['picasa']."',".$result['error'].")";
		echo $sql;
	$db->nonquery("insert into chapterk_content_bk(chap_id,manga,chap_content,error,chap_page) values(".$chap.",".$manga.",'".$result['picasa']."',".$result['error'].",".$result['page'].")");
	echo "Insert error  ".mysql_error()." -";
	echo $_GET['chap_id']."\n";
	$db->close();
	
	
	
	
}
?>